package com.ycf.demo1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Looper;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.ycf.demo1.service.GetQQ;
import com.ycf.demo1.service.Login;

public class MainActivity extends AppCompatActivity {

    EditText usernameEdit, passwordEdit;
    String username, password;

    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


    }

    /**
     *点击登录按钮后
     * @param view
     */
    public void Login(View view) {
        usernameEdit = findViewById(R.id.usernameEdit);
        username = usernameEdit.getText().toString();
        passwordEdit = findViewById(R.id.passwordEdit);
        password = passwordEdit.getText().toString();

        textView = findViewById(R.id.text);



        new Thread(){
            @Override
            public void run() {
                try {
                    Looper.prepare();
                    String info = new Login().userLogin(username, password);
                    if ("登陆成功".equals(info)) {
                        Intent intent = new Intent(MainActivity.this, MyActivity.class);
                        Bundle bundle = new Bundle();
                        String qq = new GetQQ().getQQ(username);
                        bundle.putCharSequence("qq",qq);
                        intent.putExtras(bundle);
                        startActivity(intent);
                    }else {
                        Toast.makeText(MainActivity.this, info, Toast.LENGTH_LONG).show();

                    }

                    Looper.loop();
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        }.start();


    }

    public void register(View view) {
        Intent intent = new Intent(MainActivity.this, RegisterActivity.class);
        startActivity(intent);

    }
}
